package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.*;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface OrderMapper {



    void add(Orders orders);


    /**
     * 查询历史订单
     * @param ordersPageQueryDTO
     * @return
     */
    @Options(keyProperty = "id",useGeneratedKeys = true)
    Page<Orders> selectHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 通过订单id查询订单详情表
     */
    @Select("select * from order_detail where order_id=#{orderId}")
    List<OrderDetail> selectOrderDetail(Long orderId);


    /**
     * 各个状态下的订单数量统计
     */
    @Select("select count(*) from orders where status=#{status}")
    int statistics(Integer status);

    /**
     * 接单
     * @param ordersConfirmDTO
     */
    @Update("update orders set status=#{status} where id =#{id}")
    void OrdersConfirm(OrdersConfirmDTO ordersConfirmDTO);

    /**
     * 完成订单
     */
    @Update("update orders set status=#{status} where id =#{id}")
    void OrdersComplete(Long id ,Integer status);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select *from orders where id=#{id}")
    Orders getById(Long id);

    @Update("update orders set pay_status=#{payStatus} ,status=#{status},cancel_reason=#{cancelReason},cancel_time=#{cancelTime}")
    void update(Orders orders);
}
